from rich.console import Console
console = Console()# console初始化

# console可以自动发现一些terminal的attribute
console.print('[bold italic red]Some attributions')
print('size: ',console.size)# 输出terminal的尺寸
print('encoding: ',console.encoding)# 输出terminal的编码方式
print('is_terminal: ',console.is_terminal)# 输出terminal是否为终端，当该attribute为None时，颜色无法显示
print('color_system: ',console.color_system)# 终端的颜色格式

# Print
console.print('[bold italic red]Start test print method')
console.print([1,2,3])# 非string会进行简单的色彩填充
console.print("[blue underline]Looks like a link")# string 会输入到rich.print方法中
console.print(locals())
console.print({'a':1, 'b':2})
console.print("FOO", style="white on blue")
console.print('[bold red on yellow] what [/] [blue] name[/]')

# Log
console.print('Start test log method', style='bold italic red')
def test_log():
    a = 1
    b = 2
    c = [1,2,3]
    console.log('test log',log_locals=True)
console.log('Hello world!')# log函数自带时间戳
test_log()

# Justify
# 用来将输入输出左右对齐，参数有left, right, center, full,其中 full为两端对齐
concole = Console(width=20)
style = 'bold white on blue'
console.print("Rich", style=style)
console.print("Rich", style=style, justify="left")# 使用对齐之后没有字符的部分会使用空格填充
console.print("Rich", style=style, justify="center")
console.print("Rich", style=style, justify="right")

# Input
concole = Console()
a = console.input('What is [i]your[/i] [bold red]name[/]? :smiley:  ')# same to input()
print(a)

# Export
console = Console(record=True)
console.print('Test export', style='bold white on black')
console.log('Test export')

print(console.export_text(clear=False))# 返回一个string
console.save_html('console.html', clear=False)# save as a html,默认有style，html看起来更方便
console.save_text('console.txt')# save as a txt,默认没有style







